﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace Cashier.utils
{
    public class MailUtil
    {
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static bool Send(String subject, String body)
        {
            bool isSend = false;
            try
            {
                MailMessage message = new MailMessage("daysmei@126.com", "316218370@qq.com");
                message.Subject = subject;
                message.SubjectEncoding = Encoding.UTF8;
                message.Body = body;
                message.BodyEncoding = Encoding.UTF8;
                message.IsBodyHtml = false;
                message.Priority = MailPriority.Normal;

                SmtpClient smtp = new SmtpClient("smtp.126.com", 25);
                smtp.Timeout = 0;
                NetworkCredential credential = new NetworkCredential("daysmei@126.com", "840925");
                smtp.Credentials = credential;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.EnableSsl = true;
                smtp.Send(message);
                isSend = true;
            }
            catch
            {}
            return isSend;
        }
    }
}
